// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi 
// Source File Name:   MsgConfigInfo.java

package com.vandagroup.common.msg;

import java.io.PrintStream;
import java.sql.*;
import java.util.*;

// Referenced classes of package com.vandagroup.common.msg:
//            MsgConnection

public class MsgConfigInfo
{

    private static HashMap msgStruCon = null;
    private static HashMap msgMainCon = null;
    public static final String SNDRCVFLGUP = "1";
    public static final String SNDRCVFLGDOWN = "2";

    public MsgConfigInfo()
    {
    }

    public static void init()
    {
    }

    public static void loadInfo()
        throws Exception
    {
        Statement stmt = null;
        MsgConnection mc = new MsgConnection();
        mc.begin();
        stmt = mc.getConn().createStatement();
        ResultSet rs = stmt.executeQuery("select MSGCODE,TRANCODE,CNAME,MSGCOUNT from msgMainCon");
        HashMap ht = null;
        msgMainCon = new HashMap();
        msgStruCon = new HashMap();
        for(; rs.next(); msgMainCon.put(rs.getString("MSGCODE").trim(), ht))
        {
            ht = new HashMap();
            ht.put("TRANCODE", rs.getString("TRANCODE").trim());
            ht.put("CNAME", rs.getString("CNAME") == null ? "" : ((Object) (rs.getString("CNAME").trim())));
            ht.put("MSGCOUNT", rs.getString("MSGCOUNT") == null ? "0" : ((Object) (rs.getString("MSGCOUNT"))));
        }

        rs = stmt.executeQuery("select MSGCODE,SNDRCVFLG,ENAME,CNAME,DTYPE,HOSTENAME,FLAG,DEFAULTVALUE from msgStruCon");
        HashMap hm = null;
        for(; rs.next(); putMsgStruCon(rs.getString("MSGCODE").trim(), rs.getString("SNDRCVFLG"), rs.getString("ENAME").trim(), hm))
        {
            hm = new HashMap();
            hm.put("CNAME", rs.getString("CNAME").trim());
            hm.put("DTYPE", rs.getString("DTYPE").trim());
            hm.put("HOSTENAME", rs.getString("HOSTENAME").trim());
            hm.put("FLAG", rs.getString("FLAG"));
            if(rs.getString("DEFAULTVALUE") != null)
                hm.put("DEFAULTVALUE", rs.getString("DEFAULTVALUE").trim());
            else
                hm.put("DEFAULTVALUE", "");
        }

        mc.free();
    }

    private static void putMsgStruCon(String msgCode, String sndRcvFlg, String eName, HashMap v)
    {
        if(msgStruCon == null)
        {
            HashMap hm1 = new HashMap();
            hm1.put(eName, v);
            HashMap hm2 = new HashMap();
            hm2.put(sndRcvFlg, hm1);
            msgStruCon = new HashMap();
            msgStruCon.put(msgCode, hm2);
        } else
        if(msgStruCon.get(msgCode) == null)
        {
            HashMap hm1 = new HashMap();
            hm1.put(eName, v);
            HashMap hm2 = new HashMap();
            hm2.put(sndRcvFlg, hm1);
            msgStruCon.put(msgCode, hm2);
        } else
        if(((HashMap)msgStruCon.get(msgCode)).get(sndRcvFlg) == null)
        {
            HashMap hm1 = new HashMap();
            hm1.put(eName, v);
            HashMap hm2 = (HashMap)msgStruCon.get(msgCode);
            hm2.put(sndRcvFlg, hm1);
        } else
        {
            HashMap hm1 = (HashMap)((HashMap)msgStruCon.get(msgCode)).get(sndRcvFlg);
            hm1.put(eName, v);
        }
    }

    public static HashMap getMsgStruCon(String msgCode, String sndRcvFlg, String eName)
    {
        if(msgMainCon != null)
        {
            HashMap ht = (HashMap)msgStruCon.get(msgCode);
            if(ht != null)
            {
                ht = (HashMap)ht.get(sndRcvFlg);
                if(ht != null)
                {
                    ht = (HashMap)ht.get(eName);
                    return ht;
                }
            }
        }
        return null;
    }

    public static String getTransCode(String msgCode)
        throws Exception
    {
        if(msgMainCon == null)
            loadInfo();
        HashMap hm = (HashMap)msgMainCon.get(msgCode);
        return (String)hm.get("TRANCODE");
    }

    public static int getTransCount(String msgCode)
        throws Exception
    {
        if(msgMainCon == null)
            loadInfo();
        try
        {
            HashMap hm = (HashMap)msgMainCon.get(msgCode);
            return Integer.parseInt((String)hm.get("MSGCOUNT"));
        }
        catch(Exception e)
        {
            return 0;
        }
    }

    public static String getTransUpItem(String msgCode, String name)
        throws Exception
    {
        if(msgStruCon == null)
            loadInfo();
        HashMap hm = getMsgStruCon(msgCode, "1", name);
        try
        {
            return (String)hm.get("HOSTENAME");
        }
        catch(Exception e)
        {
            return name;
        }
    }

    public static HashMap getTransUpSet(String msgCode)
        throws Exception
    {
        if(msgStruCon == null)
            loadInfo();
        HashMap hm = (HashMap)msgStruCon.get(msgCode);
        if(hm == null)
            return null;
        else
            return (HashMap)hm.get("1");
    }

    public static String getTransDownItem(String msgCode, String name)
        throws Exception
    {
        if(msgStruCon == null)
            loadInfo();
        HashMap hm = getMsgStruCon(msgCode, "2", name);
        return (String)hm.get("HOSTENAME");
    }

    public static String getTransUpDefValue(String msgCode, String name)
        throws Exception
    {
        if(msgStruCon == null)
            loadInfo();
        HashMap hm = getMsgStruCon(msgCode, "1", name);
        return (String)hm.get("DEFAULTVALUE");
    }

    public static void dispkey(HashMap hm)
    {
        Set keySet = hm.keySet();
        Iterator keyIterator = keySet.iterator();
        String key = null;
        for(; keyIterator.hasNext(); System.out.println(key + ":\t" + hm.get(key)))
            key = (String)keyIterator.next();

        System.out.println("==============");
    }

}
